home *** CD-ROM | disk | FTP | other *** search
/ Practical Algorithms for Image Analysis / Practical Algorithms for Image Analysis.iso / CH_5.1 / PCCDE / PCCDE.C < prev    next >
Encoding:
C/C++ Source or Header  |  1999-09-11  |  2.7 KB  |  113 lines

  1. /* 
  2.  * pccde.c
  3.  * 
  4.  * Practical Algorithms for Image Analysis
  5.  * 
  6.  * Copyright (c) 1997, 1998, 1999 MLMSoftwareGroup, LLC
  7.  */
  8.  
  9. /* PCCDE:       program decodes primitives chain code (PCC) from file
  10.  *            and writes output image
  11.  *                      usage: pccde infile.pcc outfile.img
  12.  *
  13.  */
  14.  
  15. #include <stdio.h>
  16. #include <stdlib.h>
  17. #include <string.h>
  18. #include <tiffimage.h>          /* tiff file format info */
  19. #include <images.h>             /* images information file */
  20. #include "pcc2.h"               /* header file for PCC programs */
  21. extern void print_sos_lic ();
  22.  
  23. unsigned char *fcCode;          /* code storage */
  24. long nByteCode;                 /* no. bytes in storage */
  25.  
  26. int input (int, char **);
  27. int usage (short);
  28.  
  29. main (argc, argv)
  30.      int argc;
  31.      char *argv[];
  32. {
  33.   Image *imgO;                  /* output image structure */
  34.   unsigned char **image;        /* image array */
  35.   long widthO, heightO;         /* output image size */
  36.  
  37.   if ((input (argc, argv)) < 0)
  38.     return (-1);
  39.  
  40. /* open input PCC file */
  41.   if (pccread (argv[1], &fcCode, &nByteCode, &widthO, &heightO) == -1)
  42.     exit (1);
  43.   printf ("image size: %dx%d, PCC length = %d\n",
  44.           widthO, heightO, nByteCode);
  45.  
  46. /* allocate output image */
  47.   imgO = ImageAlloc (heightO, widthO, 8);
  48.   image = ImageGetPtr (imgO);
  49.  
  50. /* construct tables of feature chain decodes */
  51.   pccdecodes ();
  52.  
  53. /* perform feature chain decoding */
  54.   printf ("decoding being performed\n");
  55.   pccdecode (image, widthO, heightO, 0);
  56.  
  57. /* write image output file */
  58.   printf ("output image being written\n");
  59.   ImageOut (argv[2], imgO);
  60.  
  61.   return (0);
  62. }
  63.  
  64.  
  65. /* USAGE:       function gives instructions on usage of program
  66.  *                    usage: usage (flag)
  67.  *              When flag is 1, the long message is given, 0 gives short.
  68.  */
  69.  
  70. usage (flag)
  71.      short flag;                /* flag =1 for long message; =0 for short message */
  72. {
  73.  
  74. /* print short usage message or long */
  75.   printf ("USAGE: pccde infile outimg [-L]\n");
  76.   if (flag == 0)
  77.     return (-1);
  78.  
  79.   printf ("\npccde decodes Primitives Chain Code (PCC)\n");
  80.   printf ("in input file to output image.\n\n");
  81.   printf ("ARGUMENTS:\n");
  82.   printf ("   infile: input file containing PCC (BINARY)\n");
  83.   printf ("   outimg: output image filename (TIF)\n\n");
  84.   printf ("OPTIONS:\n");
  85.   printf ("       -L: print Software License for this module\n");
  86.  
  87.   return (-1);
  88. }
  89.  
  90.  
  91. /* INPUT:       function reads input parameters
  92.  *                  usage: input (argc, argv)
  93.  */
  94.  
  95. #define USAGE_EXIT(VALUE) {usage (VALUE); return (-1);}
  96.  
  97. input (argc, argv)
  98.      int argc;
  99.      char *argv[];
  100. {
  101.  
  102.   if (argc == 1)
  103.     USAGE_EXIT (1);
  104.   if (argc == 2)
  105.     USAGE_EXIT (0);
  106.   if (argc == 4 && strcmp (argv[3], "-L") == 0) {
  107.     print_sos_lic ();
  108.     exit (0);
  109.   }
  110.  
  111.   return (0);
  112. }
  113.